#ifndef SEARCH_CITY_H
#define SEARCH_CITY_H

#include <QWidget>
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QEvent>
#include <QFile>
#include <QMessageBox>
#include <QTextStream>
#include <QDebug>
#include <QMouseEvent>
#include <QEvent>

struct CityInfo {
    QString id;
    QString name;
};

class Search_city : public QWidget
{
    Q_OBJECT
public:
    explicit Search_city(QWidget *parent = nullptr);
    
signals:
    // 新增信号：搜索到城市后传递城市ID
    void cityIdChanged(const QString &cityId);
    
private:
    QLineEdit *m_searchEdit;   // 搜索输入框
    QLabel *m_searchBtn;       // 搜索按钮（QLabel 实现）
    QLabel *m_locationLabel;   // 显示城市的标签
    QString m_currentCityId;   // 存储匹配到的城市 ID
    
    void initUI();
    
    // 从 city.txt 搜索城市
    CityInfo searchCity(const QString &cityName);
    // 处理搜索逻辑
    void onSearch();
    
    bool eventFilter(QObject *obj, QEvent *event);
};

#endif // SEARCH_CITY_H
